<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_detail.css">

    <!-- 引入 editor.md 的依赖 -->
    <link rel="stylesheet" href="editor.md/css/editormd.min.css" />
    <!-- 引入jquery -->
    <!-- <script src="js/jquery.min.js"></script> -->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="editor.md/editormd.js"></script>

</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">博客系统</span>
        <!-- spacer 不实现任何内容 只是占位 把后面a标签撑到右侧去 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>
        <a href="#" id="delete-btn">删除</a>
    </div>


    <div class="container">
        <!-- 左侧用户信息 -->
        <div class="container-left">
            <!-- 用这个元素表示用户信息 -->
            <div class="card">
                <!-- 头像 -->
                <img src="img/tx.jpg" alt="">
                <!-- 姓名 -->
                <h3></h3>
                <a href="#">github地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>1</span>
                    <span>2</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容区域 -->
        <div class="container-right">
            <div class="blog-detail">
                <h3></h3>
                <div class="date"></div>
                <!-- 设置半透明 -->
                <div id="content" style="background-color: transparent">

                </div>
            </div>
        </div>
    </div>
    <!-- 通过ajax获取到博客详情内容 -->
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/app.js"></script>
    <script>
        function getBlog() {
            $.ajax({
                type: 'get',
                // location。search获取到query string
                url: 'blog' + location.search,
                success: function (body) {
                    let h3 = document.querySelector('.blog-detail>h3');
                    h3.innerHTML = body.title;

                    let dateDiv = document.querySelector('.blog-detail>.date');
                    dateDiv.innerHTML = body.postTime;

                    // let contentDiv=document.querySelector('#content');
                    // contentDiv=innerHTML=body.content;

                    //此处使用editor.md进行渲染
                    //                    这里一定是id
                    editormd.markdownToHTML('content', { markdown: body.content });

                }
            });
        }
        getBlog();

        getLoginStatus();

        function getUserInfo() {
            $.ajax({
                type: 'get',
                url: 'userInfo' + location.search,
                success: function (body) {
                    let h3 = document.querySelector('.container-left>.card>h3');
                    h3.innerHTML = body.username;
                }
            });
        }
        getUserInfo();

        
        //将blogId加上
        function updateDelteURL(){
            let deleteBtn=document.querySelector('#delete-btn');
            deleteBtn.href='blog_delete'+location.search;
        }
        updateDelteURL();
    </script>

</body>

</html>